var oLanguageTemp = null;
jQuery.fn.dataTableExt.oApi.fnPagingInfo = function ( oSettings )
		{
			return {
				"iStart":         oSettings._iDisplayStart,
				"iEnd":           oSettings.fnDisplayEnd(),
				"iLength":        oSettings._iDisplayLength,
				"iTotal":         oSettings.fnRecordsTotal(),
				"iFilteredTotal": oSettings.fnRecordsDisplay(),
				"iPage":          oSettings._iDisplayLength === -1 ?
					0 : Math.ceil( oSettings._iDisplayStart / oSettings._iDisplayLength ),
				"iTotalPages":    oSettings._iDisplayLength === -1 ?
					0 : Math.ceil( oSettings.fnRecordsDisplay() / oSettings._iDisplayLength )
			};
		};

	
	function dataTable(data) {
		oLanguageTemp=data;
		var oLanguage = data.split(",");


		$("#userdata").dataTable( {
			"bJQueryUI": true,
			"sPaginationType": "full_numbers",
			"oLanguage": {
	            "oPaginate": {
	                          "sFirst": oLanguage[0],// ปุ่มกลับมาหน้าแรก
	                          "sLast": oLanguage[1],//ปุ่มไปหน้าสุดท้าย
	                          "sNext": oLanguage[2], //ปุ่มหน้าถัดไป
	                          "sPrevious": oLanguage[3] // ปุ่ม กลับ
	                        	  },
	             "sLengthMenu": oLanguage[4],  
	             "sZeroRecords": oLanguage[5], 
	             "sInfo": oLanguage[6],
	             "sEmptyTable": oLanguage[7],
	             "sLoadingRecords": oLanguage[8],
	             "sProcessing": oLanguage[9],
	             "sInfoEmpty": oLanguage[10],
	             "sInfoFiltered": oLanguage[11]
	        },
			"fnRowCallback" : function(nRow, aData, iDisplayIndex){
                $("td:first", nRow).html(iDisplayIndex +1);
               return nRow;
            },
            "data" : {
                "vaUserId": $("#vaUserId").val(),
                "vaName"  : $("#vaName").val()
            },
	        "bProcessing": true,
//	        "bServerSide": true,
//	        "sort": "position",
	        "bStateSave": false,
	        "iDisplayLength": 10,
	        "iDisplayStart": 0,
	        "fnDrawCallback": function () {   
	        },         
	        "fnServerParams": function ( aoData ) {
	        	  aoData.push( { "name": "vaUserId", "value": $("#vaUserId").val() } );
	        	  aoData.push( { "name": "vaName", "value": $("#vaName").val() } );
	        	},
	        "sAjaxSource": "userDataTables",
	        "aoColumns": [
				{ "mData": null,sClass: "center", sWidth: '5%'},
				{ "mData": "vaUserId",sClass: "left", sWidth: '10%' },
				{ "mData": "vaName",sClass: "left", sWidth: '20%'  },
				{ "mData": "vaPosition"},
				{ "mData": "vaStatus","mRender": function ( data, type, full ) {
					if(full.vaStatus=='I'){
						return "<i class='fa fa-times' style='color: coral'></i>";
					} else {
						return "<i class='fa fa-check' style='color: lawngreen'></i>";
					}
				    }
				,sClass: "left", sWidth: '10%' },
				{ "mData": null,"mRender": function ( data, type, full ) {
					var poObject = [full.vaApplicationId,full.vaApplicationName,full.vaImageUrl,full.vaLink];
					
				    return "<button onclick=\"editData('"+full.vaUserId+"')\" class='btn btn-info btn-sm'><i class='fa fa-edit'></i></button>";
				    }
				, sWidth: '10%',sClass: "center"},
	        ]} 
		);
		
		$('#chk-all').click(function()	{
			if($(this).is(':checked'))	{
				$('#responsiveTable').find('.chk-row').each(function()	{
					$(this).prop('checked', true);
					$(this).parent().parent().parent().addClass('selected');
				});
			}
			else	{
				$('#responsiveTable').find('.chk-row').each(function()	{
					$(this).prop('checked' , false);
					$(this).parent().parent().parent().removeClass('selected');
				});
			}
		});
	}
	
	function searchUser(data){
		$('#userdata').dataTable().fnClearTable();
		$('#userdata').dataTable().fnDestroy();
		dataTable(data);
	}
	
	function editData(data){
		window.location.href = "../user?vaUserId="+data;
	}
	